package JSON_Temp_Test;

import com.alibaba.fastjson.annotation.JSONField;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class Temp implements WritableComparable<Temp> {
    private int id;
    @JSONField(format = "yyyy-MM-dd")
    private String date;
    private int temp;

    public int compareTo(Temp o) {
        return ((Integer.parseInt(this.date.split("-")[1])) - (Integer.parseInt(o.date.split("-")[1])));
    }

    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(id);
        dataOutput.writeUTF(date);
        dataOutput.writeInt(temp);
    }

    public void readFields(DataInput dataInput) throws IOException {
        id = dataInput.readInt();
        date = dataInput.readUTF();
        temp = dataInput.readInt();
    }

    public void set(int id, String date, int temp) {
        this.id = id;
        this.date = date;
        this.temp = temp;
    }

    @Override
    public String toString() {
        return id+"\t"+date+"\t"+temp;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public int getTemp() {
        return temp;
    }

    public void setTemp(int temp) {
        this.temp = temp;
    }
}

